<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS基础方法</title>
    <!-- 外部样式 -->
    <!-- <script src="JS/scriptJS.js"></script> -->
</head>
<body>
    <!-- 内部样式 -->
    <!-- <script>
        alert("Hello JS");
    </script> -->

    <script>
        // 变量 & 数据类型
        // 对于类型 let是最常用的，任何类型都可以使用这个
        let a = 10;
        console.log(typeof a); // 查看a 的日志，typeof 查看数据类型
        a = "abc";
        console.log(typeof a);
        a = true;
        console.log(typeof a);

        let b;
        console.log(typeof b);

        // 运算符，对于运算法来说和 Java 的差不多，但是多出一些特殊运算符
        let aa = 10;
        let bb = "10";
        console.log("aa == bb : " + (aa == bb)); // 比较值，不比较类型
        console.log("aa === bb : " + (aa === bb)); // 值和类型都进行比较

        //数组定义
        let array = [];
        let array2= [10, "a", true];
        //取值
        console.log(array2[0]);
        console.log(array2[1]);
        //添加
        array2[3] = "b";
        console.log(array2);

        array2[100] = "b";
        console.log(array2.length);
        //修改
        array2[0] = 20;
        console.log(array2);
        //删除
        array2.splice(1, 1);  // 第一个参数为删除的下标, 第二个参数为删除的个数
        console.log(array2);

        array2["中文"] = "dddd";
        console.log(array2);

        //函数定义
        sum(10,20,30);
        function sum(x, y){
            console.log(x + y);
        }

        
        let sum = function(x,y){
            console.log(x + y);
        }
        
        sum(10,20);

        //对象定义
        let student = {};
        let student2 = {
            "name": "zhangsan",
            "age": 15
        };

        //读
        console.log(student2.name);
        console.log(student2["name"]);
        //修改
        student2.name = "lisi";
        console.log(student2.name);
        console.log(student2);
        //添加
        student.name = "空对象赋值";
        console.log(student);
        
    </script>
</body>
</html>